// 把类当做参数类型的泛型类

// 定义一个User类，这个类的作用就是映射数据库字段
// 然后定义一个MysqlDb的类这个类用于操作数据库
// 然后把User类作为参数传入到MysqlDb中
/**class User{
  username: string | undefined;
  password: string | undefined;
}

class MysqlDb {
  add(user: User): boolean {
    return true
  }
}

var u = new User()
u.username = '张三'
u.password = '123455'

var Db = new MysqlDb()
Db.add(u)

class ArticleCate {
  title: string | undefined;
  desc: string | undefined;
  status: number | undefined;
}

class MysqlDbA {
  add(info: ArticleCate): boolean {
    console.log(info)
    return true
  }
}

var a = new ArticleCate()
a.title = '国内'
a.desc = '国内新闻'
a.status = 1
var Db2 = new MysqlDbA()
Db2.add(a)
**/


// 想给User表增加数据
// 1.定义一个User类,和数据库进行映射
class MysqlDb<T> {
  add(info: T): boolean {
    console.log(info)
    return true
  }
  updated(info: T, id:number): boolean {
    console.log(info);
    console.log(id);
    return true
  }
}
class User {
  username: string | undefined;
  password: string | undefined;
}
var u = new User()
u.username = '张三'
u.password = '12344'
var Db = new MysqlDb<User>()
Db.add(u)

// 2. 定义一个ArticleCate类，和数据库进行映射
class ArticleCate {
  title: string | undefined;
  desc: string | undefined;
  status: number | undefined;
  constructor(params: {
    title: string | undefined,
    desc: string | undefined,
    status?: number | undefined
  }) {
    this.title = params.title
    this.desc = params.desc
    this.status = params.status
  }
}
// 增加操作
var a = new ArticleCate({
  title: '分类',
  desc: '12345'
})
// 类当做参数的泛型类
var Db2 = new MysqlDb<ArticleCate>()
// Db2.add(a)
Db2.updated(a, 12)



export {}

